package cn.slipi.admin.task;

import cn.slipi.admin.common.utils.dozer.impl.ConvertBean;
import cn.slipi.admin.dao.TSysAdminLogMapper;
import cn.slipi.admin.entity.TSysAdminLog;
import cn.slipi.admin.service.dto.in.m.SysAdminLogDTO;
import org.apache.commons.lang3.StringEscapeUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

/**
 * TODO: 请添加描述
 *
 * @author lee
 * @date 2019/4/25
 * @since 1.0.0
 */
@Component
public class LogTask {


    @Autowired
    private ConvertBean convertBean;

    @Autowired
    private TSysAdminLogMapper adminLogMapper;

    @Async
    public void writeLog(Integer userId, Integer type, String subject, String content) {
        SysAdminLogDTO adminLogDTO = new SysAdminLogDTO();
        adminLogDTO.setType(type);
        adminLogDTO.setSubject(subject);
        adminLogDTO.setContent(StringEscapeUtils.escapeHtml4(content));
        adminLogDTO.setAdminId(userId);
        TSysAdminLog adminLog = new TSysAdminLog();
        this.convertBean.convert(adminLogDTO, adminLog);
        this.adminLogMapper.insert(adminLog);
    }


}
